package com.example.ranl_offershow.Service.Impl;

import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.ranl_offershow.Dao.TestDbMapper;
import com.example.ranl_offershow.Entity.Data.OfferData;
import com.example.ranl_offershow.Listener.ImportDataListener;
import com.example.ranl_offershow.Service.TestService;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

@Service
public class TestServiceImpl extends ServiceImpl<TestDbMapper, OfferData> implements TestService {

    @Autowired
    private ImportDataListener importDataListener;

    @SneakyThrows
    @Override
    public void importExcel(MultipartFile multipartFile) {
        InputStream inputStream = multipartFile.getInputStream();
        // 这里 需要指定读用哪个class去读，然后读取第一个sheet 文件流会自动关闭
        EasyExcel.read(inputStream, OfferData.class, importDataListener).sheet().doRead();
    }
}
